﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace Chromatics.Pages
{
    public partial class CongratilationsPage : PhoneApplicationPage
    {
        public CongratilationsPage()
        {
            InitializeComponent();
            int easyMax = DataLoader.Instance.LevelsCount(Difficulty.Easy)*3;
            int medMax = DataLoader.Instance.LevelsCount(Difficulty.Medium)*3;
            int hardMax = DataLoader.Instance.LevelsCount(Difficulty.Hard)*3;
            int easyCount = 0,medCount=0,hardCount=0;
            LevelStatus curStat;
            //easy
            for(int i = 0; i < DataLoader.Instance.LevelsCount(Difficulty.Easy); ++i)
            {
                curStat = DataLoader.Instance.LoadLevelInfo(i + 1, Difficulty.Easy).Status;
                if(curStat == LevelStatus.Star1)
                    easyCount +=1;
                else if(curStat == LevelStatus.Star2)
                    easyCount +=2;
                else if(curStat == LevelStatus.Star3)
                    easyCount +=3;
            }
            //medium
            for (int i = 0; i < DataLoader.Instance.LevelsCount(Difficulty.Medium); ++i)
            {
                curStat = DataLoader.Instance.LoadLevelInfo(i + 1, Difficulty.Medium).Status;
                if (curStat == LevelStatus.Star1)
                    medCount += 1;
                else if (curStat == LevelStatus.Star2)
                    medCount += 2;
                else if (curStat == LevelStatus.Star3)
                    medCount += 3;
            }
            //hard
            for (int i = 0; i < DataLoader.Instance.LevelsCount(Difficulty.Hard); ++i)
            {
                curStat = DataLoader.Instance.LoadLevelInfo(i + 1, Difficulty.Hard).Status;
                if (curStat == LevelStatus.Star1)
                    hardCount += 1;
                else if (curStat == LevelStatus.Star2)
                    hardCount += 2;
                else if (curStat == LevelStatus.Star3)
                    hardCount += 3;
            }
            easyWin.Text = easyCount.ToString() + " / " + easyMax.ToString();
            medWin.Text = medCount.ToString() + " / " + medMax.ToString();
            hardWin.Text = hardCount.ToString() + " / " + hardMax.ToString();
        }

        private void OkBtn_Click(object sender, RoutedEventArgs e)
        {
            SoundPlayer.PlayDing();
            NavigationService.Navigate(new Uri("/MainPage.xaml", System.UriKind.Relative));
        }
    }
}